// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class AggregationRange
{
	/// <summary>
	/// <para>Start of the range (inclusive).</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("from")]
	public double? From { get; set; }

	/// <summary>
	/// <para>Custom key to return the range with.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("key")]
	public string? Key { get; set; }

	/// <summary>
	/// <para>End of the range (exclusive).</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("to")]
	public double? To { get; set; }
}

public sealed partial class AggregationRangeDescriptor : SerializableDescriptor<AggregationRangeDescriptor>
{
	internal AggregationRangeDescriptor(Action<AggregationRangeDescriptor> configure) => configure.Invoke(this);

	public AggregationRangeDescriptor() : base()
	{
	}

	private double? FromValue { get; set; }
	private string? KeyValue { get; set; }
	private double? ToValue { get; set; }

	/// <summary>
	/// <para>Start of the range (inclusive).</para>
	/// </summary>
	public AggregationRangeDescriptor From(double? from)
	{
		FromValue = from;
		return Self;
	}

	/// <summary>
	/// <para>Custom key to return the range with.</para>
	/// </summary>
	public AggregationRangeDescriptor Key(string? key)
	{
		KeyValue = key;
		return Self;
	}

	/// <summary>
	/// <para>End of the range (exclusive).</para>
	/// </summary>
	public AggregationRangeDescriptor To(double? to)
	{
		ToValue = to;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FromValue.HasValue)
		{
			writer.WritePropertyName("from");
			writer.WriteNumberValue(FromValue.Value);
		}

		if (!string.IsNullOrEmpty(KeyValue))
		{
			writer.WritePropertyName("key");
			writer.WriteStringValue(KeyValue);
		}

		if (ToValue.HasValue)
		{
			writer.WritePropertyName("to");
			writer.WriteNumberValue(ToValue.Value);
		}

		writer.WriteEndObject();
	}
}